package com.cci.kangdao.service.impl;

import com.cci.kangdao.dao.*;
import com.cci.kangdao.dto.response.GetDictionariesConfigListByTypeResponse;
import com.cci.kangdao.service.*;
import com.cci.kangdao.utilTool.ParameterTool;
import org.apache.commons.collections4.MapUtils;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("DictionariesConfigService")
public class DictionariesConfigImpl implements DictionariesConfigService {

    private Logger log = Logger.getLogger(this.getClass().getName());


    @Resource
    private DictionariesConfigTDao dictionariesConfigTDao;

    /**
     * 根据类型获取字典配置表数据接口
     */
    @Override
    public ModelAndView getDictionariesConfigListByType(Map<String, Object> map) {
        HttpServletResponse response = (HttpServletResponse) map.get("response");
        int dictionariesConfigType = MapUtils.getIntValue(map,"DictionariesConfigType",-1);
        if(dictionariesConfigType == -1){
            ParameterTool.writeResponse(response, 17,"缺少必要参数！");
            return null;
        }
        List<GetDictionariesConfigListByTypeResponse> dictionariesConfigList = dictionariesConfigTDao.getDictionariesConfigListByType(dictionariesConfigType);
        Map<String,Object> data = new HashMap<>();
        data.put("DictionariesConfigList",dictionariesConfigList);
        ParameterTool.writeSuccessResponse(response, data);
        return null;
    }
}
